
import 'dart:ui';
import 'package:cached_network_image/cached_network_image.dart';

import 'package:du_application/provide/person.dart';
import 'package:du_application/routes/application.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:provide/provide.dart';
import '../../conpoments/bottomBar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../units/iconfont.dart';
import './PersonCenterBar.dart';
class PersonCeter extends StatelessWidget {
  const PersonCeter({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
     Provide.value<PersonProvide>(context).getUserInfo(context);
    ScrollController controller = ScrollController();
   final _loadingContainer = Container(
      width: ScreenUtil().setHeight(1080),
      height: ScreenUtil().setHeight(1920),
      constraints: BoxConstraints.expand(),
      color: Colors.black,
      child: Center(
        child: Opacity(
          opacity: 0.9,
          child: SpinKitWave(
            color: Colors.white,
            size: 50.0,
          ),
        ),
      ));

    return Provide<PersonProvide>(
      builder: (context, child, index) {
        return index == null ||
                index.userInfoModel == null ||
                index.userInfoModel.data == null
            ? _loadingContainer
            : Scaffold(
                bottomNavigationBar: BottomBar(),
                body: ListView(
                  shrinkWrap: true,
                  controller: controller,
                  // crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Stack(
                      children: <Widget>[
                        Container(
                        margin: EdgeInsets.only(
                            bottom: ScreenUtil.getInstance().setWidth(5)),
                        width: ScreenUtil.getInstance().setWidth(1080),
                        color: Colors.white,
                        child: Row(
                          children: <Widget>[
                            Container(
                                decoration: BoxDecoration(
                                  borderRadius:
                                   BorderRadius.all(Radius.circular(9999)),
                                ),
                                margin: EdgeInsets.all(
                                    ScreenUtil.getInstance().setSp(40)),
                                height: ScreenUtil.getInstance().setWidth(200),
                                width: ScreenUtil.getInstance().setWidth(200),
                                child: ClipOval(
                                  child: CachedNetworkImage(
                                    height:  ScreenUtil.getInstance().setWidth(200),
                                    width: ScreenUtil.getInstance().setWidth(200),
                                    imageUrl: index.userInfoModel.data.avatar,
                                    fit: BoxFit.cover,
                                  placeholder: (context, url) =>
                                        Image.asset('assets/loading.jpg',width: ScreenUtil().setWidth(200),height: ScreenUtil().setWidth(200),),
                                    // print("111");
                                  ),
                                )),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: <Widget>[
                                Container(
                                    width: ScreenUtil().setWidth(550),
                                    child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      children: <Widget>[
                                        Container(
                                          width: ScreenUtil().setWidth(450),
                                          child: Text(
                                            index.userInfoModel.data.nickName,
                                            maxLines: 1,
                                            style: TextStyle(
                                                fontWeight: FontWeight.w500,
                                                fontSize:
                                                    ScreenUtil.getInstance()
                                                        .setSp(60)),
                                            textAlign: TextAlign.start,
                                          ),
                                        ),
                                        Container(
                                            child: index.userInfoModel.data
                                                        .gender ==
                                                    0
                                                ? Icon(
                                                    IconFont.icon_nan,
                                                    color: Colors.blue,
                                                  )
                                                : Icon(
                                                    IconFont.icon_nv,
                                                    color: Colors.pink,
                                                  )),
                            
                                      ],
                                    )
                                    ),
                            Container(
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.start,
                                children: <Widget>[
                                   Text(
                                    "关注",
                                    style: TextStyle(color: Colors.grey),
                                   ),
                                   Text(
                                    "粉丝",
                                    style: TextStyle(color: Colors.grey), ),
                              
                                ],
                              )
                            ),
                              ],
                            )
                          ],
                        )),
                           Positioned(
                             right: 0,
                             top: ScreenUtil().setHeight(40),
                             child: FlatButton(
                              onPressed: () {
                               Application.router
                               .navigateTo(context, "/info");
                                },
                               child: Container(
                                child: Icon(
                                Icons.settings,
                                color: Colors.cyan[400],
                                size: ScreenUtil.getInstance()
                                .setSp(40),
                                )),
                                ),
                               ),
                      ],
                    ),
                 
                    Container(
                        padding:
                            EdgeInsets.symmetric(horizontal: 20, vertical: 10),
                        color: Colors.white,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: <Widget>[
                            Expanded(
                              flex: 1,
                              child: Container(
                                //  decoration: BoxDecoration(
                                //    border: Border(right: BorderSide(width: 1,color: Colors.grey))),
                                child: InkWell(
                                  child: Row(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceBetween,
                                    children: <Widget>[
                                      FlatButton.icon(
                                        icon: Icon(IconFont.icon_shop),
                                        label: Text("购买"),
                                        onPressed: () {},
                                      ),
                                      Row(
                                        children: <Widget>[
                                          Text(
                                              index.userInfoModel.data.order
                                                  .toString(),
                                              style: TextStyle(
                                                  color: Colors.grey[600],
                                                  fontSize: 12)),
                                          Icon(
                                            Icons.arrow_forward_ios,
                                            color: Colors.grey[200],
                                            size: 10,
                                          ),
                                        ],
                                      ),
                                    ],
                                  ),
                                  onTap: () {
                                    Application.router
                                        .navigateTo(context, "/order");
                                  },
                                ),
                              ),
                            ),
                            Expanded(
                              flex: 1,
                              child: InkWell(
                                onTap: (){
                                        Application.router
                                        .navigateTo(context, "/collect");
                                },
                                child: Container(
                                  child: Row(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceBetween,
                                    children: <Widget>[
                                      FlatButton.icon(
                                        icon: Icon(IconFont.icon_star),
                                        label: Text("收藏"),
                                        onPressed: () {},
                                      ),
                                      Row(
                                        children: <Widget>[
                                          Text(
                                              index.userInfoModel.data.collect
                                                  .toString(),
                                              style: TextStyle(
                                                  color: Colors.grey[600],
                                                  fontSize: 12)),
                                          Icon(
                                            Icons.arrow_forward_ios,
                                            color: Colors.grey[200],
                                            size: 10,
                                          ),
                                        ],
                                      ),
                                    ],
                                  ),
                                )
                              ),
                            ),
                          ],
                        )),
                    Container(
                      margin: EdgeInsets.only(top: 5),
                      padding:
                          EdgeInsets.symmetric(horizontal: 20, vertical: 10),
                      color: Colors.white,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          FlatButton.icon(
                            icon: Icon(IconFont.icon_dongtai),
                            label: Text("发布新动态"),
                            onPressed: () {
                              Application.router.navigateTo(context, "/image");
                            },
                          ),
                     
                        ],
                      ),
                    ),
                   //选择左右
                   Container(
          margin: EdgeInsets.only(top: 5.0),
          child: Column(
            children: <Widget>[
              Row(
                children: <Widget>[
               InkWell(
      onTap: (){
         Provide.value<PersonProvide>(context).changeLeftAndRight('left');
      },
      child: Container(
       
      padding:EdgeInsets.all(20.0),
        alignment: Alignment.center,
        width: ScreenUtil().setWidth(540),
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
            bottom: BorderSide(
              width: 1.0,
              color: index.isLeft?Colors.black:Colors.white,
            )
          )
        ),
        child: Text(
          '动态',
          style: TextStyle(
            color:index.isLeft?Colors.black:Colors.grey 
          ),
        ),
      ),
    ),
    InkWell(
      onTap: (){
      
        Provide.value<PersonProvide>(context).changeLeftAndRight('right');
      },
      child: Container(
         
        padding:EdgeInsets.all(20.0),
        alignment: Alignment.center,
        width: ScreenUtil().setWidth(540),
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
            bottom: BorderSide(
              width: 1.0,
              color: index.isRight?Colors.black:Colors.white 
            )
          )
        ),
        child: Text(
          '喜欢',
          style: TextStyle(
            color:index.isRight?Colors.black:Colors.grey 
          ),
        ),
      ),
    )
                ],
              ),
            ],
          ),
        ),
                   
                   //选择左右,
                    //开始

        index.isLeft?StaggeredGridView.countBuilder(
       controller: controller,
      shrinkWrap: true,
      physics: NeverScrollableScrollPhysics(),
      padding: const EdgeInsets.all(8.0),
      crossAxisCount: 4,
      itemCount:index.userInfoModel.data.myAffair.length,
      itemBuilder: (context, i) {
        String imgPath =  index.userInfoModel.data.myAffair[i].affair.url;
        return new Material(
         
          child: new InkWell(
            onTap: () {
            Application.router.navigateTo(context, "/affairDetail?id=${index.userInfoModel.data.myAffair[i].affair.id}");
            },
            child: Column(
              children: <Widget>[
                Stack(
                  children: <Widget>[
                    Container(
                      child: Hero(
                        tag: index.userInfoModel.data.myAffair[i].affair.id,
                        child: Stack(
                          alignment: Alignment.bottomCenter,
                          children: <Widget>[
                            CachedNetworkImage(
                              imageUrl: imgPath,
                              fit: BoxFit.fitWidth,
                              placeholder: (context, url) =>
                                  Image.asset('assets/loading.jpg'),
                              // print("111");
                            ),
                            Container(
                              height: 50,
                              decoration: new BoxDecoration(
                                gradient: LinearGradient(
                                    begin: Alignment.bottomCenter,
                                    end: Alignment.topCenter,
                                    colors: [
                                      Color.fromRGBO(0, 0, 0, 0.5),
                                      // Color.fromRGBO(0, 0, 0, 0.5),
                                      Color.fromRGBO(0, 0, 0, 0)
                                    ]),
                              ),
                              //  color: Color.fromRGBO(0, 0, 0, 0.1),
                            )
                          ],
                        ),
                      ),
                    ),
                    Positioned(
                      bottom: ScreenUtil().setWidth(20),
                      left: ScreenUtil().setWidth(15),
                      child: Icon(
                        Icons.looks,
                        color: Colors.white,
                      ),
                    ),
                    Positioned(
                        bottom: ScreenUtil().setWidth(25),
                        left: ScreenUtil().setWidth(65),
                        child: Text(
                          "29",
                          style: TextStyle(color: Colors.white),
                        )),
                  ],
                ),
                Container(
                  margin:
                      EdgeInsets.symmetric(vertical: ScreenUtil().setSp(20)),
                  width: ScreenUtil().setWidth(500),
                  child: Text(
                  index.userInfoModel.data.myAffair[i].affair.content,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    textAlign: TextAlign.left,
                  ),
                ),
                Container(
                    margin: EdgeInsets.only(bottom: ScreenUtil().setSp(20)),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Row(
                          children: <Widget>[
                            Container(
                              margin: EdgeInsets.symmetric(
                              horizontal: ScreenUtil().setSp(10)),
                              width: ScreenUtil().setWidth(50),
                              height: ScreenUtil().setWidth(50),
                              child: CircleAvatar(
                                backgroundImage: NetworkImage(
                                   index.userInfoModel.data.myAffair[i].userInfo.avatarUrl),
                              ),
                            ),
                            Text(
                          index.userInfoModel.data.myAffair[i].userInfo.nickName,
                              style: TextStyle(color: Colors.grey[600]),
                            )
                          ],
                        ),
                      
                      ],
                    ))
              ],
            ),
          ),
        );
      },
      staggeredTileBuilder: (index) => new StaggeredTile.fit(2),
      mainAxisSpacing: 8.0,
      crossAxisSpacing: 8.0,
      //pengyou
    ): StaggeredGridView.countBuilder(
       controller: controller,
      shrinkWrap: true,
      physics: NeverScrollableScrollPhysics(),
      padding: const EdgeInsets.all(8.0),
      crossAxisCount: 4,
      itemCount:index.userInfoModel.data.friendAffair.length,
      itemBuilder: (context, i) {
        String imgPath = index.userInfoModel.data.friendAffair[i].affair.url;
        return new Material(
         
          child: new InkWell(
            onTap: () {
            Application.router.navigateTo(context, "/affairDetail?id=${index.userInfoModel.data.friendAffair[i].affair.id}");
            },
            child: Column(
              children: <Widget>[
                Stack(
                  children: <Widget>[
                    Container(
                      child: Hero(
                        tag: index.userInfoModel.data.friendAffair[i].affair.id,
                        child: Stack(
                          alignment: Alignment.bottomCenter,
                          children: <Widget>[
                            CachedNetworkImage(
                              imageUrl: imgPath,
                              fit: BoxFit.fitWidth,
                              placeholder: (context, url) =>
                                  Image.asset('assets/loading.jpg'),
                              // print("111");
                            ),
                            Container(
                              height: 50,
                              decoration: new BoxDecoration(
                                gradient: LinearGradient(
                                    begin: Alignment.bottomCenter,
                                    end: Alignment.topCenter,
                                    colors: [
                                      Color.fromRGBO(0, 0, 0, 0.5),
                                      // Color.fromRGBO(0, 0, 0, 0.5),
                                      Color.fromRGBO(0, 0, 0, 0)
                                    ]),
                              ),
                              //  color: Color.fromRGBO(0, 0, 0, 0.1),
                            )
                          ],
                        ),
                      ),
                    ),
                    Positioned(
                      bottom: ScreenUtil().setWidth(20),
                      left: ScreenUtil().setWidth(15),
                      child: Icon(
                        Icons.looks,
                        color: Colors.white,
                      ),
                    ),
                    Positioned(
                        bottom: ScreenUtil().setWidth(25),
                        left: ScreenUtil().setWidth(65),
                        child: Text(
                          "29",
                          style: TextStyle(color: Colors.white),
                        )),
                  ],
                ),
                Container(
                  margin:
                      EdgeInsets.symmetric(vertical: ScreenUtil().setSp(20)),
                  width: ScreenUtil().setWidth(500),
                  child: Text(
                  index.userInfoModel.data.friendAffair[i].affair.content,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    textAlign: TextAlign.left,
                  ),
                ),
                Container(
                    margin: EdgeInsets.only(bottom: ScreenUtil().setSp(20)),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Row(
                          children: <Widget>[
                            Container(
                              margin: EdgeInsets.symmetric(
                              horizontal: ScreenUtil().setSp(10)),
                              width: ScreenUtil().setWidth(50),
                              height: ScreenUtil().setWidth(50),
                              child: CircleAvatar(
                                backgroundImage: NetworkImage(
                                  index.userInfoModel.data.friendAffair[i].userInfo.avatarUrl),
                              ),
                            ),
                            Text(
                         index.userInfoModel.data.friendAffair[i].userInfo.nickName,
                              style: TextStyle(color: Colors.grey[600]),
                            )
                          ],
                        ),
                      
                      ],
                    ))
              ],
            ),
          ),
        );
      },
      staggeredTileBuilder: (index) => new StaggeredTile.fit(2),
      mainAxisSpacing: 8.0,
      crossAxisSpacing: 8.0,
    )
                   
                  ],
                ),
              ); 
},

    );
  }
}


//   Widget buildStaggeredGridView() {
//     return Provide<PersonProvide>(
//       builder: (context, child, index){
//         ScrollController controller=ScrollController();
//     List<MyAffair> myAffairs=index.isLeft?index.userInfoModel.data.myAffair:index.userInfoModel.data.friendAffair;
// return 
// }
// ); 
//  }

